# Maintainer: NicoHood <archlinux {cat} nicohood {dog} de>
# PGP ID: 97312D5EB9D7AE7D0BD4307351DAE9B7C1AE9161
# Contributor: Christopher Reimer <mail+aur[at]c-reimer[dot]de>

pkgname=hyperion
pkgver=1.03.2
pkgrel=30
_commit=d3713a8ea9116c92f0a219b7114f1a8709462979
pkgdesc="An opensource 'AmbiLight' implementation"
arch=('loong64' 'x86_64')
url="https://github.com/hyperion-project/hyperion"
license=('MIT')
depends=('libusb' 'protobuf' 'python' 'qt5-base')
optdepends=('xorg-server: X11 grabbing')
makedepends=('cmake')
backup=('etc/hyperion/hyperion.config.json')
install='hyperion.install'
source=("${pkgname}-${pkgver}.tar.gz::https://github.com/hyperion-project/hyperion/archive/$_commit.tar.gz"
        "0001-Fix-no-decleration-of-assert-with-GCC-7.2.patch"
        "hyperion.sysusers"
        "hyperiond.service"
        "hyperion.install")
sha512sums=('9f0a6392d54132c82c4f62aa72fb1cee6995ecd72d49c77544e2e771391a414ba74f2bfbe68effc75c1c8b10f2b1241064581c81a1af57041c682fe4ce110430'
            '11c51f6085d78bb75a7d73372262eedc2dab84b9d37ee1850f6b8d8c9cfe85d72a69b7d755e169028c6f7150f09201ded7d32a4edf15130ca2a12a188fe5945c'
            '80764d3abdfb7e6e7f65913e9c89dd61b425ffb80e9ab4f9df7739abe32117441095ac7b45792acd5d2a516cf4aca3e21062b119f5790aae3b178036db74ce61'
            'f8c23ba920ce683e731237c164f4f70f94d635398be5cc43ce1af48bb8ab672da47397979a825a5761dacb1ae18a1c5fc840b168c8f1e3ae411908e0e92a0c5b'
            'ff5ed8ed647a621b73e922590616e4f5d63f0a7e243aa3de0f8382a835e83166a0e04944396a61a03645cc00853251690a514b3772f163f445240e4f55f18fb5')

prepare() {
    cd "${srcdir}/${pkgname}-${_commit}"
    patch -Np1 -i "${srcdir}/0001-Fix-no-decleration-of-assert-with-GCC-7.2.patch"
}

build() {
    cd "${srcdir}/${pkgname}-${_commit}"
    mkdir -p build
    cd build
    cmake -DCMAKE_INSTALL_PREFIX="${pkgdir}/usr" \
        -DCMAKE_BUILD_TYPE=Release \
        -DENABLE_QT5=ON \
        -DPLATFORM=x86 \
        -DPROTOBUF_PROTOC_EXECUTABLE=/usr/bin/protoc \
        -DUSE_SYSTEM_PROTO_LIBS=ON \
        ..
    make
}

package() {
    cd "${srcdir}/${pkgname}-${_commit}"
    cd build
    make install
    cd ..

    install -Dm 644 config/hyperion.config.json.example \
        "${pkgdir}/etc/hyperion/hyperion.config.json"

    install -Dm 644 "${srcdir}/hyperiond.service" \
        "${pkgdir}/usr/lib/systemd/system/hyperiond.service"

    rm -rf "${pkgdir}/usr/share/hyperion/service"

    install -Dm 644 "${srcdir}/hyperion.sysusers" \
        "${pkgdir}"/usr/lib/sysusers.d/hyperion.conf

    install -Dm 644 LICENSE \
        "${pkgdir}/usr/share/licenses/${pkgname}/LICENSE"
}
